<template>
  <div class="list">
    <div class="box">
      <el-button type="primary">excel导入</el-button>
      <el-button type="success">excel导出</el-button>
    </div>
    <div>
      <el-table
        ref="singleTable"
        :data="supplierSeach"
        highlight-current-row
        style="width: 100%"
        border
      >
        <el-table-column label="#" prop="id" type="index"> </el-table-column>
        <el-table-column property="date" prop="username" label="姓名">
        </el-table-column>
        <el-table-column property="name" prop="mobile" label="联系方式">
        </el-table-column>
        <el-table-column label="头像">
          <template v-slot="{ row }">
            <el-avatar :size="50" :src="row.avatar"></el-avatar>
          </template>
        </el-table-column>
        <el-table-column label="角色">
          <template #default="{ row }">
            <div v-if="row.role && row.role.length > 0">
              <el-tag v-for="item in row.role" :key="item.id" size="mini">{{
                item.title
              }}</el-tag>
            </div>
            <div v-else>
              <el-tag size="mini">{{ $t("msg.excel.defaultRole") }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="openTime" label="创建时间"> </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="mini">查看</el-button>
            <el-button size="mini">编辑</el-button>
            <el-button size="mini" type="danger" @click="getDel(scope.row._id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { ylist, clearList } from "../../api/list";
export default {
  name: "",
  data() {
    return {
      supplierSeach: [],
      page: 1,
      size: 5,
      total: 0,
    };
  },
  created() {
    this.init();
  },
  methods: {
    async init() {
      console.log(this.page, this.size);
      let res = await ylist(this.page, this.size);
      this.supplierSeach = res.list;
      this.total = res.total;
      console.log(res);
    },
    handleSizeChange(val) {
      this.size = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.init();
    },
    // 渲染
    
    // 删除
    async getDel(id) {
      // console.log(id);
      let res = await clearList(id);
      // console.log(res);
      // console.log(id);
      // alert("删除");
      // this.init()
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  height: 70px;
  width: 100%;
}
.el-button {
  float: right;
  margin-top: 14px;
  margin-left: 20px;
}
.el-table {
  margin-top: 15px;
}
</style>
